package com.stu.test.servlet;

import com.stu.test.entity.Address;
import com.stu.test.entity.User;
import com.stu.test.mapper.IAddressMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/**
 * ClassName: AddressSelectServlet
 * Package: com.stu.test.servlet
 * Description: @Version 1.0
 */
@WebServlet("/addressSelect")
public class AddressSelectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String resource = "mybatis-config.xml";
        // 读取总配置文件
        InputStream inputStream = Resources.getResourceAsStream(resource);
        // 获取session工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        // 获取session
        SqlSession session = sqlSessionFactory.openSession();

        Address address=session.getMapper(IAddressMapper.class).getAddrById(1);
        System.out.println(address);
        session.commit();

    }
}
